package com.joesem.sale.client.logic.login

import android.os.Bundle
import com.jiaxing.sale.client.R
import com.jiaxing.sale.client.databinding.ActivityLoginBinding
import com.jiaxing.sale.client.databinding.LayoutToolbarBinding
import com.joesem.sale.client.base.*
import com.joesem.sale.client.logic.home.MainActivity
import com.joesem.sale.client.utils.click
import com.joesem.sale.client.widget.dialog.optionNoticePermission

class LoginActivity : BaseActivity<ActivityLoginBinding>() {

    private val viewMode by createViewModel<LoginViewModel>()

    override fun LayoutToolbarBinding.toolbar(savedInstanceState: Bundle?) {
        visible()
        toolbarButtonLeft.gone()
        toolbarBg.setBackgroundColor(R.color.themeColor.color())
        toolbarTitle.apply {
            setTextColor(R.color.white.color())
        }.text = "登录"

    }

    override fun ActivityLoginBinding.initView(savedInstanceState: Bundle?) {
    }

    override fun ActivityLoginBinding.initListener() {
        btnLogin.click {
            val account = etAccount.text?.toString()
            val pwd = etPwd.text?.toString()
            if (account.isNullOrEmpty()) {
                toast("请输入账户名")
                return@click
            }
            if (pwd.isNullOrEmpty()) {
                toast("请输入密码")
                return@click
            }
            viewMode.login(account, pwd)
        }
        btnBackPassword.click {

        }
        btnRegister.click {
        }
    }

    override fun ActivityLoginBinding.initIntent(intent: Any?) {
        when (intent) {
            is LoginViewModel.LoginSuccessIntent -> {
                toast("登录成功")
                launch<MainActivity>()
                finish()
            }
        }
    }
}